﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CashierSystem.CashierInManager;

namespace CashierSystem.CheckItemManager
{
    public partial class AddCheckItemForm : Form
    {
        public AddCheckItemForm()
        {
            InitializeComponent();
        }

        string[] departId;
        string[] departName;
        string[] doctorId;
        string[] doctorName;

        private void AddCheckItemForm_Load(object sender, EventArgs e)
        {
            CashierInManager.CashierInManager.getDepartInfo(out departName, out departId);
            cbDepartment.Items.Clear();
            for (int i = 0; i < departId.Length; i++)
            {
                cbDepartment.Items.Add(departName[i]);
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            string itemName = tbItemName.Text;
            string price = tbPrice.Text;

            int i = cbDepartment.SelectedIndex;
            string departId1 = departId[i];

            int j = cbDoctor.SelectedIndex;
            string doctorId1 = doctorId[j];

            CheckItemManager.saveItems(itemName, price);

            string maxItemId = CheckItemManager.getMaxItemId();

            CheckItemManager.saveDoctorItem(doctorId1, maxItemId);

            CheckItemManager.saveDepartItem(departId1, maxItemId);

            DialogResult response = MessageBox.Show("添加成功！");

            cbDepartment.Text = "";
            tbItemName.Text = "";
            cbDoctor.Text = "";
            tbPrice.Text = "";



        }

        private void cbDepartment_SelectedIndexChanged(object sender, EventArgs e)
        {
            int j = cbDepartment.SelectedIndex;
            string departId1 = departId[j];
            CheckItemManager.getDoctorInfo(out doctorName, out doctorId, departId1);
            cbDoctor.Items.Clear();
            for (int i = 0; i < doctorId.Length; i++)
            {
                cbDoctor.Items.Add(doctorName[i]);
            }

        }
    }
}